#ifndef ENVIRONMENT_H
#define ENVIRONMENT_H

#include <defs/export.h>
#include <defs/global.h>
#include <core/entityobject.h>

namespace Optra{ namespace Extensions {
    class Context;
}}

namespace Opl { namespace Helpers {  namespace Support{

O_PRIVATE_DECLARE(Environment);

/*!
 Environmant class
 */
class HELPERS_EXPORT Environment : public Opl::Core::EntityObject {
    Q_OBJECT
public:
	enum SearchPathMode{
		system_path			= 0x01,
		optra_applications	= 0x02,
		script_sdk_include	= 0x04,
		zones_applications	= 0x08,
		zones_plugins		= 0x10,
		//0x20,
		applications = optra_applications | zones_applications,
		all = system_path | script_sdk_include |zones_plugins | applications
	};

	Q_ENUMS(SearchPathMode)
	Q_DECLARE_FLAGS(SearchPathModes, SearchPathMode)

	Environment(Opl::Core::EntityObject *parent);
	virtual ~Environment();

	/*!
	  Expands path, replace defines proper values:
	  $BINDIR
	  $ROOT
	  $PATH
	  */
	Q_INVOKABLE QString expandPath(const QString path, const Optra::Extensions::Context* context);

	/*!
	  Expands path, replace defines proper values:
	  $BINDIR
	  $ROOT
	  $PATH
	  */
	Q_INVOKABLE QString expandPath(SearchPathMode mode, const QString& path);


	/*!
	 Find file in search path
	 return full path to first found ot empty
	 \sa searchPath
	 */
	Q_INVOKABLE QString findFile(const QString& filename, SearchPathModes mode = all);

	/*!
	 return search paths "System path splited", and application exe dir
	 \sa findFile
	 */
	Q_INVOKABLE QStringList searchPath(SearchPathModes mode);

	Q_INVOKABLE QString username();

	enum DirectoryKind{
		UserDirectory,
		DocumentsDirectory

	};

	Q_ENUMS(DirectoryKind)

	Q_INVOKABLE QDir getDirectoryLocation(DirectoryKind dir);
	
	static Environment* instance();
	
private:
	O_PRIVATE_DECLARE_MEMBER(Environment)
};

}}}

Q_DECLARE_OPERATORS_FOR_FLAGS(Opl::Helpers::Support::Environment::SearchPathModes)

#endif // ENVIRONMENT_H

